<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择优惠券</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/style.css">
    <script src="/static/layui/jquery.min.js"></script>
    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/xyl.js"></script>
</head>
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <fieldset class="layui-elem-field">
            <legend>条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane" action="{:url('/store/market/coupon/option')}" method="GET">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">优惠券类型</label>
                            <div class="layui-input-inline">
                                <select name="coupon_type">
                                    <option value=""></option>
                                    <option value="1">满减卷</option>
                                    <option value="2">立减劵</option>
                                    <option value="3">拼团卷</option>
                                    <option value="4">转卖卷</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">优惠券名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword"  placeholder="请输入优惠名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button  class="layui-btn" lay-submit lay-filter="search">搜索</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <form class="layui-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th><input type="checkbox" lay-skin="primary" title="全选" id="parent" lay-filter="parent"></th>
                    <th>优惠券图标</th>
                    <th>优惠券类型</th>
                    <th>优惠券名称</th>
                    <th>数量</th>
                    <th>到期时间</th>
                    <th>发放数量</th>
                </tr>
                </thead>
                <tbody>

                {foreach $list as $vo}
                <tr>
                    <td><input type="checkbox" lay-filter="son"  class="son" lay-skin="primary" value="{$vo.id}" title="{$vo.id}"></td>
                    <td><img src="{$vo.icon}" class="layui-view-img coupon-icon"></td>
                    <td>{$vo.coupon_type}</td>
                    <td class="coupon-name">{$vo.coupon_name}</td>
                    <td>{$vo.quota}</td>
                    <td>
                        {if $vo.expire_type==1}
                            领取后{$vo.expire_day}天有效
                        {elseif $vo.expire_type==2}
                            {$vo.start_time}~{$vo.end_time}
                        {/if}
                    </td>
                    <td><input type="number" value="1" class="layui-input give_num"></td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </form>
        {$list|raw}
    </div>
</div>
<script>
    layui.use('form',function(){
        var form = layui.form;
        form.on('checkbox(parent)',function(data){
            selected(data.elem.checked);
        })

        function selected(checked){
            $('.son').each(function(){
                $(this).prop('checked',checked);
            });
            form.render('checkbox');
        }

        form.on('checkbox(son)',function(data){
            sonSelected();
        })

        function sonSelected(){
            let son = $('.son');
            let count = 0;
            son.each(function(){
                if($(this).prop('checked')){
                    count++;
                }
            });

            $('#parent').prop('checked',son.length == count);
            form.render('checkbox');
        }

    });
</script>
</body>
</html>